package com.kitty.game.talk.model;

import org.codehaus.jackson.annotate.JsonIgnoreProperties;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.HashMap;
import java.util.Map;

/**
 * 记录正在进行的对话，便于弹出下一对话
 * 不需要入库
 */
@JsonIgnoreProperties(ignoreUnknown =true)
public class RoleTalk {
    Logger logger = LoggerFactory.getLogger(getClass());
    /**没有对话时更新为这个值*/
    public static final short NONE_TALK_ID = -1;

    /**正在进行的对话id, 弹出对话时更新*/
    private int talkId = NONE_TALK_ID;

    /**对话时有些选择的值进行临时保存*/
    private Map<String, Object> chooseParams;

    /**开始对话，记录对话id*/
    public void startTalk(int talkId) {
        logger.info("开始记录对话：{}", talkId);
        this.talkId = talkId;
    }

    /**继续对话，记录对话id*/
    public void continueTalk(int talkId) {
        logger.info("继续对话：{}", talkId);
        this.talkId = talkId;
    }

    /**结束对话，重置对话id*/
    public void endTalk() {
        logger.info("结束对话：{}", talkId);
        this.talkId = NONE_TALK_ID;
    }

    public int getTalkId() {
        return talkId;
    }

    /**是否在对话中*/
    public boolean isInTalk() {
        if (talkId != NONE_TALK_ID) {
            return true;
        }
        return false;
    }

    /**保存临时选项参数*/
    public Object pushChooseParam(String key, Object value) {
        if (chooseParams == null) {chooseParams = new HashMap<>(2) ;}

        return chooseParams.put(key, value);
    }

    /**弹出临时选项参数*/
    public Object popChooseParam(String key) {
        if (chooseParams == null) {return null;}

        return chooseParams.remove(key);
    }
}
